using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

// Separate implementation of the components of the BLBase class for easy transference to the DL
public class InternalComponents : MonoBehaviour {

	
    public struct Mismatches
    {
        string user;
        string caseID;
        string timestamp;
        string question;
        string nlpQuestion;
        string answer;
    }
	
	// Config variables.
	// public static string DatabaseConnectionString = "Server=localhost;Database=VP_OFP;User ID=admin;Password=pass;Pooling=true";
		
    // Case Id variables
    public static string m_strAvailableCaseID;     

    /*
     *  The following elements are complementary to the available case,
     *  as of 5/8/2012 they have not been assigned in any particular stage of the process,
     *  but are used at the BLAskingQuestions.cs and DLAskingQuestions.cs
     *  I (Andres Ramirez) suggests that they are assigned either at BLAskingQuestions, or at
     *  BLSessionSelection.
     *  
     *  Please change this comment when this is done, please take into account that this changes
     *  must also be supported by a query counterpart.
     */
    public string m_strTypeOfCaseID;        
    public string m_strTypeOfQuestionsID;   
    public string m_strCaseRelatedRolesID;  
    
    // Score from the asking question section
    public static int m_iTotalScore;

    // Score from the final questions system
    public static int m_iFinalStateScore;

    // General progress information
    public static int m_iQuestionsAsked;
    public static int m_iQuestionsFailed;
    public static int m_iFinalChoicesMade;
    public static int m_iFinalChoicesFailed;

    // Date and time information
    public static string m_strDate;
    public static string m_strTimeInit;
    public static string m_strTimeFinish;

    //Time limit information
    public static DateTime m_dtTimeStart;
    public static bool m_bHasStarted = false;
	
    // List of questions asked
    public static List<string> m_lQuestionsAsked = null;
    public static List<Mismatches> m_lMismatches = null;
	
    // create list function
    public static void CreateList()
    {
        m_lQuestionsAsked = new List<string>();
        m_lMismatches = new List<Mismatches>();
    }
	
	void Start(){
		DontDestroyOnLoad(transform.gameObject);
	}
}

public class CCase
{
    // Base reference to what defines a case for logical purposes
    private string m_pName;
    private string m_pDescription;
    private string m_pID;
    private int m_pTries;

    // Accessors
    public string m_Name
    {
        get
        {
            return m_pName;
        }
        set
        {
            m_pName = value;
        }
    }

    public string m_Description
    {
        get
        {
            return m_pDescription;
        }
        set
        {
            m_pDescription = value;
        }
    }

    public string m_ID
    {
        get
        {
            return m_pID;
        }
        set
        {
            m_pID = value;
        }
    }

    public int m_Tries
    {
        get
        {
            return m_pTries;
        }
        set
        {
            m_pTries = value;
        }
    }

    //------------------------------------------------------------------------------
    // Methods of the class BLAskingQuestions
    //------------------------------------------------------------------------------

    public static bool SetUpList(out List<CCase> finalList, string[] names, string[] description, string[] id, int size)
    {
        finalList = new List<CCase>();

        for (int i = 0; i < size; i++)
        {
            CCase baseCase = new CCase();

            baseCase.m_Name = names[i];
            baseCase.m_Description = description[i];
            baseCase.m_ID = id[i];

            finalList.Add(baseCase);
        }

        return true;
    }

    public static bool SetUpList(out List<CCase> finalList, string[] names, string[] description, int[] id, int[] tries, int[] userTries, int size)
    {
        finalList = new List<CCase>();

        for (int i = 0; i < size; i++)
        {
            if(tries[i] == -1){
                CreateEntry(finalList, names[i], description[i], id[i], tries[i]);
            }
            else if(userTries[i] <= tries[i]){
                CreateEntry(finalList, names[i], description[i], id[i], tries[i]);
            }
        }

        return true;
    }

    private static bool CreateEntry(List<CCase> finalList, string names, string description, int id, int tries)
    {
        CCase baseCase = new CCase();

        baseCase.m_Name = names;
        baseCase.m_Description = description;
        baseCase.m_ID = id.ToString();
        baseCase.m_Tries = tries;
        finalList.Add(baseCase);
        return true;
    }

}
